package CTRLayer;

import java.util.Date;
import java.util.ArrayList;
import DBLayer.*;
import ModelLayer.*;

public class tController {

	private IFDBCustomer customerDB;
	private IFDBSupplier supplierDB;
	private IFDBLocation locationDB;
	private IFDBSalesLine salesLineDB;
	private IFDBSalesOrder salesOrderDB;
	private IFDBProduct productDB;
	private IFDBDelivery deliveryDB;
	
	public tController(){
		customerDB = new DbCustomer();
		supplierDB = new DbSupplier();
		locationDB = new DbLocation();
		salesOrderDB = new DbSalesOrder();
		productDB = new DbProduct();
		deliveryDB = new DbDelivery();
	}
	
	public void createOrder(int cusID, Date creationDate, Date paymentDate, int amount, String status, double discount, int deliveryId, ArrayList<SalesLine> salesList) {
		SalesOrder so = new SalesOrder();
		so.setAmount(amount);
		so.setC(customerDB.getCustomerById(cusID));
		so.setD(deliveryDB.getDeliveryById(deliveryId));
		so.setCreationDate(creationDate);
		so.setPaymentDate(paymentDate);
		so.setStatus(status);
		so.setDiscount(discount);
		so.setSl(salesList);
		try {
			salesOrderDB.insertSalesOrder(so);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public boolean deleteOrder(int idSelected) {
		if(salesOrderDB.deleteSalesOrder(salesOrderDB.searchSalesOrder(idSelected))==-1)
			return false;
		else
			return true;
	}
	
	public ArrayList<Product> listAllProducts() {
		return productDB.getAllProducts();
	}
	
	public ArrayList<Customer> listAllCustomers(){
		return customerDB.getAllCustomers();
	}
	
	public ArrayList<Delivery> listAllDelivery(){
		return deliveryDB.getAllDelivery();
	}
	
	public ArrayList<SalesOrder> listAllOrders(){
		return salesOrderDB.getAllSalesOrder();
	}
	
	public Product getProductById(int id)
	{
		return productDB.searchProductById(id);
	}
}
